package com.easyenglishcenter.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.logging.Logger;

public class ContactServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(ContactServlet.class.getName());

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String msgBody = "Name: " + request.getParameter("Field6") + " " + request.getParameter("Field7") + "\nEmail: "
                + request.getParameter("Field2") + "\nMessage: " + request.getParameter("Field1");
        String subject = "My Cafe Talk: Web Contact";
        String toEmail = "contact@mycafetalk.com";
        String toName = "Contact My Cafe Talk";
        Email email = new Email();
        email.sendEmail(msgBody, toEmail, toName, subject);
        log.info(msgBody);
        request.setAttribute("msg", "Message sent.");
        request.getRequestDispatcher("contact.jsp").forward(request, response);

    }
}
